package LeetCode.Simple;

import java.util.ArrayDeque;

/**
 * 定义一个函数，输入一个链表的头节点，反转该链表并输出反转后链表的头节点。
 * 示例:
 * 输入: 1->2->3->4->5->NULL
 * 输出: 5->4->3->2->1->NULL
 * 反转链表
 */
public class Question011 {
    public ListNode reverseList(ListNode head) {
        ListNode newHead = null;
        ListNode oldHead = head;
        while(oldHead != null){
            ListNode next = oldHead.next;
            oldHead.next = newHead;
            newHead = oldHead;
            oldHead = next;

        }
//        ArrayDeque<Integer> stack = new ArrayDeque<>();
//        if(head == null){
//            return null;
//        }
//        stack.push(head.val);
//        while(head.next != null){
//            stack.push(head.next.val);
//            head=head.next;
//        }
//        ListNode newHead = new ListNode(stack.pop());
//        ListNode p = newHead;
//        while(stack.isEmpty()){
//            int a = stack.pop();
//            System.out.println(a);
//            p = p.next;
//            p.val = a;
//        }
        return newHead;
    }
}
